package com.example.week2.Retrofit;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.HashMap;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Body;

//6.Retrofit封装网络框架单例类
public class RetrofitManager{
    private static RetrofitManager retrofitManager;
    public static RetrofitManager getInstance(){
        if(retrofitManager==null){
            retrofitManager=new RetrofitManager();
        }
        return retrofitManager;
    }

    private Retrofit retrofit;
    public Retrofit getRetrofit() {
        if(retrofit==null){
            create();
        }
        return retrofit;
    }

    private String baseUrl="http://172.81.227.127:8055/swagger-ui.html#!/user45controller/";
    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }
    private void create() {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .build();
        retrofit= new Retrofit.Builder()
                .baseUrl("http://172.81.227.127:8055/swagger-ui.html#!/user45controller/")
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();



    }


}
